package com.nowcoder.community.config;

import com.nowcoder.community.interceptor.DataInterceptor;
import com.nowcoder.community.interceptor.LoginTicketInterceptor;
import com.nowcoder.community.interceptor.MessageInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author szq
 * @create 2023-01-20 21:46
 * @description MVC配置类
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private final LoginTicketInterceptor loginTicketInterceptor;

    //    @Autowired
//    private LoginRequiredInterceptor loginRequiredInterceptor;

    private final MessageInterceptor messageInterceptor;

    private final DataInterceptor dataInterceptor;

    public WebMvcConfig(LoginTicketInterceptor loginTicketInterceptor, MessageInterceptor messageInterceptor, DataInterceptor dataInterceptor) {
        this.loginTicketInterceptor = loginTicketInterceptor;
        this.messageInterceptor = messageInterceptor;
        this.dataInterceptor = dataInterceptor;
    }

    // 配置拦截器，为它指定拦截、排除的路径
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> excludePathPatterns = List.of("/**/*.css", "/**/*.js", "/img/**","/editormd/**");
        registry.addInterceptor(loginTicketInterceptor)
                .excludePathPatterns(excludePathPatterns);
//        registry.addInterceptor(loginRequiredInterceptor)
//                .excludePathPatterns("/**/*.css","/**/*.js","/img/**");
        registry.addInterceptor(messageInterceptor)
                .excludePathPatterns(excludePathPatterns);
        registry.addInterceptor(dataInterceptor)
                .excludePathPatterns(excludePathPatterns);
    }
}
